import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        tagsStoreList: [],
        userData: null,
        token: null,
        tokenExpiresTime: null,
        tokenRefreshTime: null,
        router: null

    },
    mutations: {
        saveTagsData(state, data) {
            state.tagsStoreList = data;
            sessionStorage.setItem("Tags", data);
        },
        saveUserData(state, data) {
            state.userData = data;
            sessionStorage.setItem("user", data);
        },
        saveUserName(state, data) {
            state.userName = data;
            sessionStorage.setItem("UserName", data);
        },
        saveToken(state, data) {
            state.token = data;
            window.localStorage.setItem("Token", data);
        },
        savetokenExpiresTime(state, data) {
            state.tokenExpiresTime = data;
            window.localStorage.setItem("TokenExpiresTime", data);
        },
        saveRefreshTime(state, data) { //刷新时间
            state.tokenRefreshTime = data;
            window.localStorage.setItem("TokenRefreshTime", data);

        },
        saveRouter(state, data) {
            state.router = data;
            window.localStorage.setItem("Router", data);
        },
        getToken() {
            return window.localStorage.getItem("Token");
        },
        getTokenExpiresTime() {
            return window.localStorage.getItem("TokenExpiresTime");

        },
        getRefreshTime() { //刷新时间
            return window.localStorage.getItem("TokenRefreshTime");

        },

        clearAllItem() {
            this.commit("saveTagsData", "");
            this.commit("saveUserData", "");
            this.commit("saveUserName", "");
            this.commit("saveToken", "");
            this.commit("savetokenExpiresTime", "");
            this.commit("saveRefreshTime", "");
            this.commit("saveRouter", "");
        }
    },
})

// 应用初始状态
// const state = {
//     tagsStoreList: [],
//     userData: null,
//     token: null,
//     tokenExpiresTime: null,
//     tokenRefreshTime: null
//         //  userName:null,
// }

// // 定义所需的 mutations


// // 创建 store 实例
// export default new Vuex.Store({
//     actions,
//     getters,
//     state,
//     mutations
// })